home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8747 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Running out of memory with mmap
  5. Followup-To: comp.unix.programmer
  6. Date: 6 Mar 1996 00:27:38 -0800
  7. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  8. Message-ID: <4hji9qINNopi@keats.ugrad.cs.ubc.ca>
  9. References: <4hiq9o$h18@news.acns.nwu.edu>
  10. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  11. Keywords: mmap
  12.  
  13. In article <4hiq9o$h18@news.acns.nwu.edu>,
  14. George Johnson <johnson@immuno.bme.nwu.edu> wrote:
  15.  >
  16.  >Hi folks--
  17.  >
  18.  >
  19.  >I have this procedure which is called a few thousand times, each time
  20.  >with different requests for information from different large files.  
  21.  >Within this procedure is :
  22.  >
  23.  >       ....
  24.  >
  25.  >    pa = mmap(0,fsiz,PROT_READ,MAP_PRIVATE,fpB,0);
  26.  >
  27.  >    madvise(pa,fsiz,MADV_RANDOM);
  28.  >
  29.  >    if ( pa == (caddr_t) -1) {
  30.  >       perror("mmap failed");
  31.  >         exit(1);
  32.  >     }
  33.  >
  34.  >    .... go to the specified offset in the file, grab the info
  35.  >
  36.  >    .... leave procedure
  37.  >
  38.  >The size of the file(s) fpB are around 20 MB a piece.  What happens
  39.  >is that after 100 or so calls, the program exits saying it has run
  40.  >out of memory.
  41.  >
  42.  >My question is where did the memory go?  I don't understand what is
  43.  >going on.  I free all malloc'ed stuff, there is little else going on
  44.  >in the program other than opening these big files, reading through
  45.  >them and grabbing out little pieces of information.
  46.  >
  47.  >My assumption (hehehe) from reading the manual page for mmap and 
  48.  >munmap is that when mmap is called, it unmaps implicitly anybody
  49.  >occupying space 0 to fsiz, so no munmap is needed to free up (?)
  50.  
  51. You have misread the documentation. The address zero just tells mmap() to find
  52. you a suitable region in your virtual address space to map an object. A mmap
  53. will never overlap with existing memory maps.
  54.  
  55.  >I'm not sure what I'm forgetting to do.
  56.  
  57. Use munmap(). Otherwise, you are spamming your virtual address space! 
  58.  
  59.  >Any suggestions would be very helpful.
  60.  
  61. How about this: take it to comp.unix.programmer where they would _love_ to
  62. discuss mmap() with you for the next three weeks! I would too, just not here.
  63. -- 
  64.  
  65.